<?php

namespace App\Http\Resources\Admin;

use App\Http\Resources\BaseResource;

class MenusResource extends BaseResource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'link' => $this->link,
            'icon' => $this->icon,
            'status' => $this->status,
            'weight' => $this->weight,
            'parent_id' => $this->parent_id,
            'key' => $this->key,

            // 关联信息
            'parent' => new MenusResource($this->whenLoaded('parent')),
            'children' => MenusResource::collection($this->whenLoaded('children')),

            'created_at' => $this->created_at->format('Y-m-d H:i:s')
        ];
    }
}
